package com.db.compare.controller;

import com.db.compare.core.BaseController;
import com.db.compare.core.BaseResponse;
import com.db.compare.filter.JwtAuthenticatioToken;
import com.db.compare.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;
@RequestMapping("/")
@Controller
public class LoginController extends BaseController {
    @Autowired
    private AuthenticationManager authenticationManager;

    @RequestMapping("")
    public String login(){
        return "/html/login";
    }

    @RequestMapping("/login")
    @ResponseBody
    public BaseResponse login(@RequestParam Map<String,String> param, HttpServletRequest request){
        String username=param.get("username");
        String password=param.get("password");
        JwtAuthenticatioToken token = SecurityUtils.login(request, username, password, authenticationManager);
        return buildSuccessResponse(token);
    }
}
